Mastering Bash by Giorgio Zarrelli

Mastering Bash by Giorgio Zarrelli

Author:Giorgio Zarrelli [Zarrelli, Giorgio]
Language: eng
Format: azw3, mobi, epub
Tags: COM088010 - COMPUTERS / System Administration / Linux & UNIX Administration, COM046030 - COMPUTERS / Operating Systems / UNIX, COM046070 - COMPUTERS / Operating Systems / Linux
Publisher: Packt Publishing
Published: 2017-06-21T04:00:00+00:00


Then there is something we never saw before:

| time=0.011048s;;;0.000000;10.000000

This is a pipe, followed by one or more labels, time in our example, and some values usually related to how the service is working. Whatever is written, it is not a Nagios concern, since it will not process this part of the output line. These values are there for third-party applications such as pnp4nagios or Nagios graph to process them and eventually draw out some performance graphics.

Nagios shows the performance data but does not really make use of it

We will see later how a graph for a service looks like, now let's remember one thing: the output of a plugin is usually one line long and even though you have a multiline output, it is always better to stick to a simple message.

Now, let's go back to the definition of the SSH service check, and let's see how to modify it to enable a different port check. This is the check_ssh command that we have already seen:

# 'check_ssh' command definition

define command{

command_name check_ssh

command_line /usr/lib/nagios/plugins/check_ssh '$HOSTADDRESS$'

}

To enable the definition of an arbitrary port check, we have to modify the command_line row so that it will accept the new -p parameter with an argument:

# 'check_ssh' command definition

define command{

command_name check_ssh

command_line /usr/lib/nagios/plugins/check_ssh '$HOSTADDRESS$' -p $ARG1$

}

What we did is simple: we just added a -p followed by $ARG1$. What is this new bit? In Nagios, you can pass whatever arguments you want to a script, and you refer to them using a positional variable. Think of $ARG1$ as $1 for a standard bash script; it identifies the first argument passed to the command line. Bear in mind that options like -p are not counted as arguments. So $ARG2$ will be the second positional argument, $ARG3$ the third, and so on. Do not forget the leading and trailing dollar signs. So, we modified the way Nagios can call the plugin, and now we can pass it an extra argument. What is left is to actually provide the extra argument to the script; this is done by modifying the service definition for ssh. We previously had this:

# check that ssh services are running

define service {

use generic-service

host_name localhost

service_description SSH

check_command check_ssh

}

This definition must be modified so that we can store and pass the port number to the command, so this is how we do it:

# check that ssh services are running

define service {

use generic-service

host_name localhost

service_description SSH

check_command check_ssh!1472

}

The exclamation mark (!) after the command name is a standard field separator and identifies the different positional arguments passed to the plugin. Let's make an example modifying the command_line of ssh to accept it:

-p 1472

-4

-P 2.0

-t 30

We must modify the command line to accept five parameters instead of one:

# 'check_ssh' command definition

define command{

command_name check_ssh

command_line /usr/lib/nagios/plugins/check_ssh '$HOSTADDRESS$' -p $ARG1$ -$ARG2$ -r $ARG3$ -P $ARG4$ -t $ARG5$

}

The modification is quite straightforward, we just wrote down all the switches and their arguments using the positional $ARGn$ variables. Now that the command line is ready to accept the new values, we must fill in the placeholders:

# check that



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.